package com.liaoban.app.ui.anchor;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.liaoban.app.R;
import com.liaoban.app.constants.ExtraParam;
import com.liaoban.app.ui.base.BaseActivity;
import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by ybc on 2018/8/6 0006.
 */
public class GalleryActivity extends BaseActivity {
    @BindView(R.id.pager)
    ViewPager pager;

    private List<String> images;
    private int position;
    GalleryAdapter adapter;

    public static Intent newIntent(Context context, List<String> images, int position) {
        Intent intent = new Intent();
        intent.setClass(context, GalleryActivity.class);
        intent.putStringArrayListExtra(ExtraParam.LIST, (ArrayList<String>) images);
        intent.putExtra(ExtraParam.POSITION, position);
        return intent;
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_gallery;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        images = getIntent().getStringArrayListExtra(ExtraParam.LIST);
        position = getIntent().getIntExtra(ExtraParam.POSITION, 0);

        adapter = new GalleryAdapter(getSupportFragmentManager());
        pager.setAdapter(adapter);
        pager.setCurrentItem(position);
    }

    private class GalleryAdapter extends FragmentPagerAdapter {

        public GalleryAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return images.size();
        }

        @Override
        public Fragment getItem(int position) {
            return GalleryImageFragment.newInstance(images.get(position));
        }

    }
}
